package main

import (
	"fmt"
)

//打印金字塔
func fun1(){
	var num int
	fmt.Print("请输入行数:")
	fmt.Scanln(&num)
	for i := 1;i <=num;i++{
		for j:=1;j<=num-i;j++{
			fmt.Print(" ")
		}
		for k:=1;k<=2*i-1;k++{
			fmt.Print("*")
		}
		fmt.Println("")
	}
}

//九九乘法表
func fun2(){
	for i:= 1;i<=9;i++{
		for j:=1;j<=i;j++{
			fmt.Printf("%d * %d = %d\t",j,i,i*j)
		}
		fmt.Println("")
	}
}

//map使用案例
func fun3(users map[string]map[string]string,name string){
	if(users[name]!=nil){
		users[name]["password"] = "888888"
	} else {
		users[name] = make(map[string]string,2)
		users[name]["nickname"] = "张"
		users[name]["password"] = "123456"
	}
}

func main(){
	fun1()
	fmt.Println("-----------------------------")
	fun2()
	fmt.Println("-----------------------------")

	var users map[string]map[string]string = make(map[string]map[string]string,5)
	users["李四"] = make(map[string]string,2)
	users["李四"]["password"] = "111111"
	users["李四"]["nickname"] = "李"
	users["王五"] = make(map[string]string,2)
	users["王五"]["nickname"] = "王"
	users["王五"]["password"] = "222222"
	for k,v := range users{
		fmt.Printf("key=%v,value=%v\n",k,v)
	}
	fmt.Println("-----------------------------")
	fun3(users,"李四")
	for k,v := range users{
		fmt.Printf("key=%v,value=%v\n",k,v)
	}
	fmt.Println("-----------------------------")
	fun3(users,"张三")
	for k,v := range users{
		fmt.Printf("key=%v,value=%v\n",k,v)
	}
	fmt.Println("-----------------------------")
}